function PrefController(){ }

PrefController.prototype.freeMemory = function() {
   $('#prefList').html('').listview('refresh');
};

$(function(){ 
    
    var tutorial = false;
    
    $(document).on('pagebeforeshow', '#pagePrefArchives', function(){        
        monaca.updateUIStyle("titlelable", "text", "都道府県別一覧");
        monaca.updateUIStyle("backheader", "visibility", "true");
        monaca.updateUIStyle("footer", "visibility", "true");
        monaca.updateUIStyle("mapfooter", "visibility", "true");
        
        monaca.updateUIStyle("editfooter", "visibility", "false");
        monaca.updateUIStyle("canselfooter", "visibility", "false");
        monaca.updateUIStyle("deletefooter", "visibility", "false");
        monaca.updateUIStyle("checkallfooter", "visibility", "false");
        
        Util.prototype.changeSnapperElement("prefarchives-content");
        
        $('.tutorial').hide();
        $('.prefTutorial').hide();
        tutorial = true;
    
        BookmarksService.prototype.countProductByAllPref(function(results) {
            var len = results.rows.length,
                list = '';
            if (len > 0) {            
                tutorial = false;
                for (var i=0; i<len; i++){    
                    list += "<li><a href='#' id = 'city" + results.rows.item(i).pref_no + "' class = 'bookmarkPref' prefname = "+results.rows.item(i).pref_name+">"+
                                results.rows.item(i).pref_name + "<span class='ui-li-count'>"+results.rows.item(i).prefkazu+"</span></a></li>";       
                }
            } else {
                list = '<h3>ブックマーク登録がありません</h3>';
                monaca.updateUIStyle("footer", "visibility", "false");
            }
            
            $('#prefList').append(list).listview('refresh');
            Util.prototype.hideSpinner();    
        });
    });
    
    $(document).on('pageshow', '#pagePrefArchives', function(){        
        if(tutorial){
            $('.tutorial').show("slow");
            $('.prefTutorial').show("slow");
        }
        PageChangeController.prototype.freeMemory();
    });
  
    $(document).on('tap', '.bookmarkPref', function(){
        Util.prototype.showSpinner(); 
        var params = {'cityCode': $(this).attr('id').slice(4), 'cityName': $(this).attr('prefname')};

        PageChangeController.prototype.changeToPage('pageCityArchives', params);
        return false;
    });    
});